package com.hjx.movie.core.system.controller.admin;

import com.hjx.movie.common.utils.Result;
import com.hjx.movie.common.utils.ResultType;
import com.hjx.movie.core.system.service.admin.IOrderService;
import com.hjx.movie.persistence.system.model.IvyOrder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Comparator;
import java.util.List;

/**
 * <p>Title:</p>
 * <p>Description:</p>
 *
 * @author hjx
 * @date 2021/2/15 - 14:54
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    IOrderService orderService;

    @GetMapping("/findAll")
    public Result findAllOrder(){
        List<IvyOrder> allOrder = orderService.findAll();
        return Result.success(allOrder);
    }



    @PostMapping("/add")
    public Result addOrder(@RequestBody @Valid IvyOrder order){
        log.debug("新增订单方法接收到的入参为:{}",order);
        if (orderService.addOrder(order)) {
            return Result.success("新增订单成功");
        }
        return Result.error(ResultType.USER_INPUT_ERROR,"新增订单失败,入参不符合规则,请检查入参");
    }

    @PostMapping("/update")
    public Result updateOrder(@RequestBody @Valid IvyOrder order){
        log.debug("修改订单方法接收到的入参为:{}",order);
        if (orderService.updateOrder(order)) {
            return Result.success("修改订单成功");
        }
        return Result.error(ResultType.USER_INPUT_ERROR,"修改订单失败,入参不符合规则,请检查入参");
    }

    @GetMapping("/delete")
    public Result deleteOrderById(@RequestParam("orderId") Long orderId){
        log.debug("删除订单方法接收到的入参为:{}",orderId);
        if (orderService.deleteOrder(orderId)) {
            return Result.success("删除订单成功");
        }
        return Result.error(ResultType.USER_INPUT_ERROR,"删除订单失败,入参不符合规则,请检查入参");
    }
}
